﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using HAVNet.Intros.Parsing;
using HAVNet.Intros.AST;


namespace HAVNet.Intros
{
    public class ASTBuilder
    {
        public ASTBuilder () { }

        void ts(Token t, int x)
        { }

        void nts(string t, int x)
        { }

        void lts()
        { }

        public ASTCS3 build (Stream stream, string [] ppsymbols)
        {
            Parser parser = new Parser ( new Scanner (stream), new TerminalSymbolFunction(ts), new NonTerminalSymbolFunction(nts), new LeaveNonTerminalSymbolFunction(lts) );

            parser.AddConditionalCompilationSymbols (ppsymbols) ;
            parser.Parse () ;

            return parser.ast ;
        }

        public ASTCS3 build (string fileName, string [] ppsymbols)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                ASTCS3 ast = build (fs, ppsymbols);
                fs.Close ();
                return ast;
            }
        }
    }
}
